package com.keqing.controller;

import com.ganyu.domain.ResponseResult;
import com.ganyu.domain.dto.AdminTagDto;
import com.ganyu.domain.entity.Tag;
import com.ganyu.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Autowired
    private TagService tagService;


    //查询标签
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum , Integer pageSize, AdminTagDto adminTagDto){
        return tagService.getTagList(pageNum, pageSize, adminTagDto);
    }

    //添加标签
    @PreAuthorize("@ps.hasPermission()")
    @PostMapping
    public ResponseResult insertTag(@RequestBody Tag tag){
        return tagService.insertTag(tag);
    }

    @PreAuthorize("@ps.hasPermission()")
    //删除标签
    @DeleteMapping("{id}")
    public ResponseResult deleteTag(@PathVariable("id") Long[] ids){
        return tagService.deleteTag(ids);
    }


    //根据id查询标签
    @GetMapping("/{id}")
    public ResponseResult getTagById(@PathVariable("id") Long id){
        return tagService.getTagById(id);
    }

    @PreAuthorize("@ps.hasPermission()")
    //修改标签
    @PutMapping
    public ResponseResult updateTag(@RequestBody Tag tag){
        return tagService.updateTag(tag);
    }

    //查询所有标签
    @GetMapping("/listAllTag")
    public ResponseResult getAllTag(){
        return tagService.getAllTag();
    }
}